<template>
	<view class="f26r colFff">
		<navbar background="background-image: linear-gradient(to right, #2c6739, #99c043);"
			title="邀请码" back @onBack="goBack" @topTotalHeight="topTotalHeight"
		></navbar>
		<view class="pl30r pr30r overYS"
			:style="'height: ' + 'calc(100vh - ' + calcNum + 'px);'"
		>
			<view class="h30r"
			></view>
			<image :src="shareCodeImg" mode="widthFix"
				class="wPer100" @click="cliBannerImg"
			></image>
		</view>
		<view class="h150r poFixed wPer100 bom0 left0 zIndex1">
			<view class="backImgLiGrTR2c6739a99c043 lh80r borRad40r teAliCenter mt35r ml30r mr30r"
				@click="saveToAlbum"
			>
				保存到相册
			</view>
		</view>
	</view>
</template>
<script>
import navbar from '@/components/navbar.vue'
import { imgNetUrl } from '@/utils/request.js'
import { getMyInviteCode } from "@/utils/api.js"
export default {
	components: { navbar },
	data() {
		return {
			imgNetUrl,
			token: '',
			calcNum: 0,
			shareCodeImg: ''
		}
	},
	onLoad() {
		const token = uni.getStorageSync('token');
		if(token) {
			this.token = token;
			getMyInviteCode({token}).then(res => {
				console.log(res);
				if(res.data && res.data.code_url) {
					this.shareCodeImg = this.imgNetUrl + res.data.code_url;
				}
			})
		}else {
			this.token = '';
		}
	},
	methods: {
		topTotalHeight(height) {
			// #ifdef MP-WEIXIN
				this.calcNum = height + 75;
			// #endif
			// #ifdef H5
				this.calcNum = 75;
			// #endif
		},
		goBack() {
			uni.navigateBack();
		},
		cliBannerImg() {
			uni.previewImage({
				current: 0, urls: [this.shareCodeImg]
			})
		},
		saveToAlbum() {
			uni.getImageInfo({
				src: this.shareCodeImg,
				success:res1 => {
					uni.saveImageToPhotosAlbum({
						filePath: res1.path,
						success:res2 => {
							uni.showToast({
								title: '保存成功', duration: 3000
							})
						}, fail:err2 => {
							uni.showToast({
								title: '保存失败', duration: 3000, icon: 'none'
							})
						}
					})
				}
			})
		}
	}
}
</script>
<style>
</style>